﻿using EFMYSQLTest.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFMYSQLTest.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserService _userService;
        private ILogger<UserController> _logger;
        public UserController(IUserService userService,ILogger<UserController> logger)
        {
            _userService = userService;
            _logger = logger;
        }


        [HttpPost]
        public void Post()
        {
            Stopwatch sw = new Stopwatch();
            //开始计时  
            sw.Start();

            _userService.Add();

            sw.Stop();

            _logger.LogInformation($"{sw.ElapsedMilliseconds}毫秒"); 

        }

        [HttpGet]
        public ActionResult<IEnumerable<Domain.User>> Get()
        {
            return _userService.GetList().ToList();
        }
    }
}
